from rest_framework import serializers
from .models import Genome


class GenomeSerializer(serializers.HyperlinkedModelSerializer):

    submiter = serializers.ReadOnlyField(
        source="submiter.username")

    class Meta:
        model = Genome
        fields = [
            "url",
            "id",
            "cn_name",
            "en_name",
            "latin_name",
            "tag",
            "path",
            "source",
            "version",
            "desc",
            "sub_time",
            "last_update_time",
            "submiter",
        ]
        extra_kwargs = {
            'url': {'view_name': 'genome-detail', 'lookup_field': 'pk'}
        }

    # def create(self,validated_data):
    #     g = Genome.objects.create(**validated_data)
    #     g.desc = g.generate_desc()
    #     g.save()
    #     return g
